<!DOCTYPE html>
<html>
<head>
<title>商盟统统付标准收银台接口</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php

$mer_no = $_POST ["mer_no"];
date_default_timezone_set ( "Asia/Shanghai" );
$timestamp = date ( 'YmdHis' );
$terminal_type = $_POST ["terminal_type"];
$url = 'https://test.sumpay.cn/entrance/gateway.htm';
#$url = 'https://test.sumpay.cn/entrance/gateway.htm';
$domain = $_POST ["domain"];

$mer_no = $_POST ["mer_no"];
$sub_mer_no = $_POST ["sub_mer_no"];
$trade_code = $_POST ["trade_code"];
$user_id = $_POST ["user_id"];
$order_no = $_POST ["order_no"];
$order_time = $_POST ["order_time"];
$order_amount = $_POST ["order_amount"];
$need_notify = $_POST ["need_notify"];
$notify_url = $_POST ["notify_url"];
$currency = $_POST ["currency"];
$goods_name = $_POST ["goods_name"];
$goods_num = $_POST ["goods_num"];
$goods_type = $_POST ["goods_type"];
$card_no = $_POST ["card_no"];
$realname = $_POST ["realname"];
$id_type = $_POST ["id_type"];
$id_no = $_POST ["id_no"];
$mobile_no = $_POST ["mobile_no"];
$bind_card_id = $_POST ["bind_card_id"];
$cvv = $_POST ["cvv"];
$valid_year = $_POST ["valid_year"];
$valid_month = $_POST ["valid_month"];
$period_num = $_POST ["period_num"];
$channel_mer_no = $_POST ["channel_mer_no"];
$remark = $_POST ["remark"];
$attach = $_POST ["attach"];
$user_ip_addr = $_POST ["user_ip_addr"];
$free_mark = $_POST ["free_mark"];
$return_url = $_POST ["return_url"];
$share_benefit_flag = $_POST ["share_benefit_flag"];
$share_benefit_exp = $_POST ["share_benefit_exp"];

$service = 'cn.sumpay.genero.trade.quick.pay.order.apply';

$parameters = [
	'mer_no' => $mer_no,
	'trade_code' => $trade_code,
	'user_id' => $user_id,
	'order_no' => $order_no,
	'order_amount' => $order_amount,
	'need_notify' => $need_notify,
	'notify_url' => $notify_url,
	'currency' => $currency,
	'goods_name' => $goods_name,
	'goods_num' => $goods_num,
	'goods_type' => $goods_type,
	'realname' => $realname,
	'id_type' => $id_type,
	'id_no' => $id_no,
	'user_ip_addr' => $user_ip_addr,
	'free_mark' => $free_mark,
		'app_id' => $mer_no,
		'terminal_type' => $terminal_type,
		'version' => '1.0',
		'service' => $service,
		'timestamp' => $timestamp,
		'mer_no' => $mer_no,
		'format' => 'JSON'
];

if ($sub_mer_no && "" != $sub_mer_no) {
	$parameters ['sub_mer_no'] = $sub_mer_no;
}
if ($order_time && "" != $order_time) {
	$parameters ['order_time'] = $order_time;
}
if ($card_no && "" != $card_no) {
	$parameters ['card_no'] = $card_no;
}
if ($mobile_no && "" != $mobile_no) {
	$parameters ['mobile_no'] = $mobile_no;
}
if ($bind_card_id && "" != $bind_card_id) {
	$parameters ['bind_card_id'] = $bind_card_id;
}
if ($cvv && "" != $cvv) {
	$parameters ['cvv'] = $cvv;
}
if ($valid_year && "" != $valid_year) {
	$parameters ['valid_year'] = $valid_year;
}
if ($valid_month && "" != $valid_month) {
	$parameters ['valid_month'] = $valid_month;
}
if ($period_num && "" != $period_num) {
	$parameters ['period_num'] = $period_num;
}
if ($channel_mer_no && "" != $channel_mer_no) {
	$parameters ['channel_mer_no'] = $channel_mer_no;
}
if ($remark && "" != $remark) {
	$parameters ['remark'] = $remark;
}
if ($attach && "" != $attach) {
	$parameters ['attach'] = $attach;
}
if ($return_url && "" != $return_url) {
	$parameters ['return_url'] = $return_url;
}
if ($share_benefit_flag && "" != $share_benefit_flag) {
	$parameters ['share_benefit_flag'] = $share_benefit_flag;
}
if ($share_benefit_exp && "" != $share_benefit_exp) {
	$parameters ['share_benefit_exp'] = $share_benefit_exp;
}



$encrypted_fields = array (
		"card_no",
		"realname",
		"id_no",
		"mobile_no",
		"cvv",
		"valid_year",
		"valid_month",
);
$charset_change_fields = array (
		"terminal_info"
);
$special_fields = array (
		"notify_url",
		"goods_name",
		"remark",
		"attach",
		"return_url",
		"share_benefit_exp",
		"terminal_info"
);
$json_array_fields = array();
$defaultCharset = 'UTF-8';

include '../tools/SumpayService.php';
$res = execute ( $url, 'UTF-8', $parameters, "../cer/yixuntiankong.pfx", "sumpay", "../cer/dev_pub.pem", $domain, $charset_change_fields, $encrypted_fields, $special_fields, $json_array_fields, $defaultCharset );
if($res['resp_code'] == '000000'){
	// 表示处理成功，可以处理后续业务
	if(substr ( $service, 0, 20 ) == 'fosun.sumpay.cashier'){
		$returnUrl = $res['redirect_url'];
		echo <<< HTML
<form hidden=true method=post action=$returnUrl>
<input hidden=true type=submit value=ok>
</form>
<script>
document.forms[0].submit();
</script>
HTML;
	}else{
		// 这步只是展示成功的响应，具体业务商户自己处理
		echo json_encode($res);
	}
}else{
	echo json_encode($res);
}

?>

</body>
</html>